/*
 * Copyright (c) 2024 OpenHiTLS. All rights reserved.
 * Licensed under the OpenHiTLS license.
 */
package org.openhitls.tls;

import javax.net.ssl.SSLServerSocketFactory;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;

/**
 * SSLServerSocketFactory implementation backed by openHiTLS.
 *
 * <p>This factory creates SSL server sockets for accepting TLS connections.</p>
 */
public class HiTlsSSLServerSocketFactory extends SSLServerSocketFactory {

    private final HiTlsSSLContextSpi context;

    HiTlsSSLServerSocketFactory(HiTlsSSLContextSpi context) {
        this.context = context;
    }

    @Override
    public String[] getDefaultCipherSuites() {
        return context.getEnabledCipherSuites();
    }

    @Override
    public String[] getSupportedCipherSuites() {
        return context.getSupportedCipherSuites();
    }

    @Override
    public ServerSocket createServerSocket(int port) throws IOException {
        return new HiTlsSSLServerSocket(context, port);
    }

    @Override
    public ServerSocket createServerSocket(int port, int backlog) throws IOException {
        return new HiTlsSSLServerSocket(context, port, backlog);
    }

    @Override
    public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress)
            throws IOException {
        return new HiTlsSSLServerSocket(context, port, backlog, ifAddress);
    }
}
